﻿
//var fs_maxWindow = false;
var customColumns = true;
fs.util.pageLoadFunction.push(function () {
    isKoMode = true;
    forceRate = "CM";
    fs_maxWindow = true;
    firstColumns = [
              { index: 0, headerText: "Base", edit: true, readonly: true, width: 80, rowText: "Budget" },
              { index: 1, headerText: "Actual", edit: true, readonly: true, width: 80, rowText: "Actual" },
              { index: 2, headerText: "Variance", edit: true, readonly: true, width: 80, rowText: "Variance" },
              { index: 4, headerText: "Vol", edit: true, width: 80, rowText: "Vol" },
              { index: 5, headerText: "Mix", edit: true, width: 80, rowText: "Mix" },
              { index: 6, headerText: "Price", edit: true, width: 80, rowText: "Price" },

              { index: 7, headerText: "", edit: false, width: 80, rowText: "empty", readonly: true },

              { index: 8, headerText: "Market price", edit: true, width: 80, rowText: "MP" },
              { index: 9, headerText: "First product price", edit: true, width: 80, rowText: "FPP" },
              { index: 10, headerText: "Productivity", edit: true, width: 80, rowText: "PRO" },
              { index: 11, headerText: "Pass through", edit: true, width: 80, rowText: "PT" },
              { index: 12, headerText: "Others", edit: true, width: 80, rowText: "Others" },
              { index: 7, headerText: "", edit: false, width: 80, rowText: "empty", readonly: true },

              { index: 14, headerText: "Control", edit: true, width: 80, rowText: "Control", style: "red", readonly: true },
              { index: 14, headerText: "Control", edit: true, width: 80, rowText: "Control1", style: "red", readonly: true }
            ];


    columnsCategory = [
    { colspan: 6, text: "" },
    { colspan: 3, text: "Total Variance" },
    { colspan: 0, text: "" },
    { colspan: 5, text: "Price Variance" },
    { colspan: 0, text: "" },
    { colspan: 2, text: ""}]
});
var afterSearchBinding = function (items) {
    $(items).each(function () {
        var row = this;
        if (row.datarow) {
            row["Control"] = ko.computed(function () {
                var equ = ""; //Variance", "Vol", "Mix", "Price
                equ += "(" + unWarpValue(row["Variance"]) + ")-";
                equ += "(" + unWarpValue(row["Vol"]) + ")-";
                equ += "(" + unWarpValue(row["Mix"]) + ")-";
                equ += "(" + unWarpValue(row["Price"]) + ")";
                var value = fs.util.eval(equ);
                return value;
            });
            row["Control1"] = ko.computed(function () {
                var equ = ""; //Price", "MP", "FPP", "PRO", "PT", "Others
                equ += "(" + unWarpValue(row["Price"]) + ")-";
                equ += "(" + unWarpValue(row["MP"]) + ")-";
                equ += "(" + unWarpValue(row["FPP"]) + ")-";
                equ += "(" + unWarpValue(row["PRO"]) + ")-";
                equ += "(" + unWarpValue(row["PT"]) + ")-";
                equ += "(" + unWarpValue(row["Others"]) + ")";
                var value = fs.util.eval(equ);
                return value;
            });
        }
    });
}
var readyJSON = [
{ emptyrow: true, description: "Budget", bold: true },

{ accountcode: "VM02010100", description: "Sales", unit: "", digits: 0, datarow: true, raterole: { table: "Budget", mode: "Y", field: "Budget_CM", skip: "Actual"} },
{ accountcode: "VM02010200", description: "SBEW", unit: "", digits: 0, datarow: true, raterole: { table: "Budget", mode: "Y", field: "Budget_CM", skip: "Actual"} },
{ accountcode: "VM02010300", description: "VC", unit: "", digits: 0, datarow: true, raterole: { table: "Budget", mode: "Y", field: "Budget_CM", skip: "Actual"} },
{ accountcode: "VM02010000", description: "VM", unit: "", digits: 0, datarow: true,
    Process: [{
        Field: "All",
        Exp: {
            mode: "search", fields: ["VM02010100", "VM02010200", "VM02010300"], equ: "+"
        }
    }]
},

{ emptyrow: true, description: "N-1", bold: true },
{ accountcode: "VM02020100", description: "Sales", unit: "", digits: 0, datarow: true, raterole: { table: "Actual", mode: "N-1", field: "CM", skip: "Actual"} },
{ accountcode: "VM02020200", description: "SBEW", unit: "", digits: 0, datarow: true, raterole: { table: "Actual", mode: "N-1", field: "CM", skip: "Actual"} },
{ accountcode: "VM02020300", description: "VC", unit: "", digits: 0, datarow: true, raterole: { table: "Actual", mode: "N-1", field: "CM", skip: "Actual"} },
{ accountcode: "VM02020000", description: "VM", unit: "", digits: 0, datarow: true,
    Process: [{
        Field: "All",
        Exp: {
            mode: "search", fields: ["VM02020100", "VM02020200", "VM02020300"], equ: "+"
        }
    }]
},
{ emptyrow: true, description: "FCST M-1", bold: true },
{ accountcode: "VM02030100", description: "Sales", unit: "", digits: 0, datarow: true, raterole: { table: "Forecast", mode: "Y", field: "M_1", skip: "Actual"} },
{ accountcode: "VM02030200", description: "SBEW", unit: "", digits: 0, datarow: true, raterole: { table: "Forecast", mode: "Y", field: "M_1", skip: "Actual"} },
{ accountcode: "VM02030300", description: "VC", unit: "", digits: 0, datarow: true, raterole: { table: "Forecast", mode: "Y", field: "M_1", skip: "Actual"} },
{ accountcode: "VM02030000", description: "VM", unit: "", digits: 0, datarow: true,
    Process: [{
        Field: "All",
        Exp: {
            mode: "search", fields: ["VM02030100", "VM02030200", "VM02030300"], equ: "+"
        }
    }]
},
{ emptyrow: true, description: "" },


{ accountcode: "VM02090100", hide: true, description: "SBEW Cost(first products)", datarow: true, index: 0 },
{ accountcode: "VM03090100", hide: true, description: "SBEW Cost(first products)", datarow: true, index: 0 }
];

